package com.sanjiahantang.youjiarole.module.common.presenters;

import android.content.Context;
import android.util.Log;

import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseMvpPresenter;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.module.category.views.impl.CategoryActivity;
import com.sanjiahantang.youjiarole.module.common.adapters.ShopAdapter;
import com.sanjiahantang.youjiarole.module.common.beans.ShopBean;
import com.sanjiahantang.youjiarole.module.common.models.IShopModel;
import com.sanjiahantang.youjiarole.module.common.models.impl.ShopModel;
import com.sanjiahantang.youjiarole.module.common.views.ShopView;
import com.sanjiahantang.youjiarole.module.common.views.impl.MainActivity;


/**
 * Created by zy on 2017/9/5.
 */

public class ShopPresenter extends BaseMvpPresenter<ShopView> implements CallBack<ShopBean> {
    private ShopAdapter adapter;

    private IShopModel shopModel;
    public ShopPresenter(){
        shopModel = new ShopModel();
    }
    public void getShopData(BaseMvpActivity context) {
        mView.showProgress();
        shopModel.getShopData(context,this);
    }

    @Override
    public void onSuccess(ShopBean response, Context context, Object tag) {
        if (mView == null) return;
        mView.hideProgress();
        if(response!=null)
        {
            adapter = new ShopAdapter(context, response);
            mView.shopRefresh(adapter);
        }else{
            Utils.showToast(context,"加载商城数据失败");
        }
    }

    @Override
    public void onFailure(String message) {
        if (mView == null) return;
        mView.hideProgress();
    }

    public void goPageCategory(BaseMvpActivity context) {
        goPageSimply(context, CategoryActivity.class);
    }
}
